package com.weir.myboot.email;

import java.util.Date;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;

import com.weir.myboot.StartSpringBootMain;


@SpringBootTest(classes=StartSpringBootMain.class)
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
public class SendEmailDemo {
	String sender = "lee_weir@outlook.com";
	
	@Autowired
	private JavaMailSender mailSender;
	@Test
	public void testMailSender(){
		SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
		simpleMailMessage.setFrom("1261174789@qq.com");
		simpleMailMessage.setTo(sender);
		simpleMailMessage.setSubject("Springboot邮件发送测试（勿回）");
		simpleMailMessage.setText("这个有Sprigboot的程序发送完成。date: "+new Date()+"");
		
		this.mailSender.send(simpleMailMessage);
	}
}
